package CtrLayer;

import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;

public class CtrTenant {
	
	private IFDBTenant dbTen;
	
	
	public CtrTenant(){
		dbTen = DBTenant.getInstance();
	}
	
	public ArrayList<Tenant> searchRandom(String searchF) {
		return dbTen.searchRandom(searchF);
	}
	
	
	public int getActiveTenants(){
		return dbTen.getActiveTenants();
	}
	
	public int getTenantsInArrear(){
		return dbTen.getTenantsInArrear();
	}
	
	public double geTenantsInArrear_Money(){
		return dbTen.geTenantsInArrear_Money();
	}
	
	public ArrayList<Tenant> getAll_where(String wClause){
		return dbTen.getAll_where(wClause);
	}
	
	public ArrayList<Tenant> getAll(){
		ArrayList<Tenant> tenants = new ArrayList<Tenant>();
		tenants = dbTen.getAll();
		return tenants;
	}
	
	public ArrayList<Tenant> getAllTenantsByName(String name){
		ArrayList<Tenant> tenants = new ArrayList<Tenant>();
		tenants = dbTen.getAllTenantsByName(name);
		return tenants;
	}
	
	public Tenant getTenantById(int tenantID){
		return dbTen.getTenantById(tenantID);
	}
	
	public Tenant getTenantByName(String name){
		return dbTen.getTenantByName(name);
	}
	
	public Tenant getTenantByName(String fname,String lname){
		return dbTen.getTenantByName(fname,lname);
	}
	
	public int delete(int tenantID){
		return dbTen.delete(tenantID);
	}
	
	public int insert(int pid, String fname, String lname, String address, String city, String postalCode, String country, String phone, String email, String idNo){
		Tenant ten = new Tenant(-1, fname, lname, address, city, postalCode, country, phone, email, idNo);
		int rc = -1;
		try{
			rc = dbTen.insert(ten);
		}catch(Exception e){
			e.printStackTrace();
		}
		return rc;
	}
	
	public int update(int pid, String fname, String lname, String address, String city, String postalCode, String country, String phone, String email, String idNo){
		Tenant ten = new Tenant(pid, fname, lname, address, city, postalCode, country, phone, email, idNo);
		return dbTen.update(ten);
		
	}
	
	public int insert(Tenant tenant) {
		return dbTen.insert(tenant);
	}
	
	public int update(Tenant tenant){
		return dbTen.update(tenant);
	}
}



